# 用户访问量     客户端地址：x.x.x.x   访问次数：xxxx

def webUv():
    web_log = r"D:\PycharmPythonProject\project1110\filetest\access_log"

    # 规划字典，统计次数 {"客户端IP": 次数}
    count = {}

    with open(web_log, mode="r") as fobj:
        for line in fobj:
            # 获取客户端地址
            client_ip = line.split()[0]
            if client_ip != "::1":
                if client_ip in count.keys():
                    count[client_ip] += 1
                else:
                    count[client_ip] = 1
        # 输出结果
        for ip,number in count.items():
            print("客户端地址：%s, 访问次数：%s" % (ip, number))
    # 字典输出次数 字典：{key:value}
    # 规划空字典： {"客户端IP": 次数}
    # { "1.1.1.1":1, "123.117.34.38":2 }
if __name__ == '__main__':
    webUv()






